/**
 *
 */
package cosc617_blackteam;

import java.util.ArrayList;

/**
 * @author Laura Semesky
 */
public class SystemInterface extends ObSubject {

    private Invoker invoker;
    private InfoAggregator infoagg;// if we are creating commands here

    public SystemInterface() {
        invoker = new Invoker();
        infoagg = new InfoAggregator(); // if we are creating commands here


    }

    public ArrayList<String> getDefaultMenu() {
        I_Command cmd = new CmdGetDefaultMenu(infoagg);
        Menu menu = (Menu) invoker.execute(cmd);
        ArrayList<String> output = new ArrayList<String>();

        for (MenuItem menuItem : menu) {
            output.add(menuItem.toString());

        }

        return output;
    }

    public ArrayList<String> getSpecialAttributeMenu(
            MenuSpecialAttribute attribute) {
        Menu menu;
        I_Command c = new CmdGetAttributeMenu(infoagg, attribute);
        menu = (Menu) invoker.execute(c);
        ArrayList<String> output = new ArrayList<String>();

        for (MenuItem menuItem : menu) {
            output.add(menuItem.toString());
        }

        return output;
    }

    public ArrayList<String> getComments() {
        CommentCollection comments;
        I_Command cmd = new CmdGetComments(infoagg);
        comments = (CommentCollection) invoker.execute(cmd);
        ArrayList<String> output = new ArrayList<String>();
        for (Comment comment : comments) {
            output.add(comment.toString());
        }
        return output;

    }
    
    public ArrayList<String> getApprovedComments(){
    	CommentCollection comments;
    	I_Command cmd = new CmdGetApprovedComments(infoagg);
    	comments = (CommentCollection) invoker.execute(cmd);
    	ArrayList<String> output = new ArrayList<String>();
    	for(Comment comment: comments){
    		output.add(comment.toString());
    	}
    	return output;
    }
    public ArrayList<String> getUnapprovedComments(){
    	CommentCollection comments;
    	I_Command cmd = new CmdGetUnapprovedComments(infoagg);
    	comments = (CommentCollection) invoker.execute(cmd);
    	ArrayList<String> output = new ArrayList<String>();
    	for(Comment comment: comments){
    		output.add(comment.toString());
    	}
    	return output;
    }
    public void approveComments(String[] comments){
    	
    	for(String comment : comments){
    		I_Command cmd = new CmdApproveComment(infoagg, comment);
    		invoker.execute(cmd);
    	}
    }
    
    public void createComment(String name, String comment) {
        I_Command cmd = new CmdCreateComment(infoagg, name, comment);
        invoker.execute(cmd);
    }

    public void createOrders(String[] orderStrings, Customer customer, CustomerParty party) {
        for (String order : orderStrings) {
            createOrder(order, party);

        }
    }

    public Order createOrder(String order, CustomerParty party) {
        I_Command cmd = new CmdAddOrder(infoagg, order, party);
        this.notifyObservers("New Order:\n" + order);
        return (Order) invoker.execute(cmd);

    }

    public ArrayList<String> getOrders() {
        OrderCollections orders;
        I_Command cmd = new CmdGetOrders(infoagg);
        orders = (OrderCollections) invoker.execute(cmd);
        ArrayList<String> output = new ArrayList<String>();
        for (Order order : orders) {
            output.add(order.toString());
        }
        return output;
    }

    public ArrayList<String> getTables() {
        TableCollections tables;
        I_Command cmd = new CmdGetTables(infoagg);
        tables = (TableCollections) invoker.execute(cmd);
        ArrayList<String> output = new ArrayList<String>();
        for (Table table : tables) {
            output.add(table.toString());
        }
        return output;
    }
    
    

    public boolean addParty(CustomerParty party) {
        I_Command cmd = new CmdAddParty(infoagg, party);
        return (boolean) invoker.execute(cmd);

    }

    public void removeParty(CustomerParty party) {
        I_Command cmd = new CmdRemoveParty(infoagg, party);
        invoker.execute(cmd);
    }

    public String getStatistics() {
        I_Command cmd = new CmdGetStatistics(infoagg);
        return (String) invoker.execute(cmd);
    }

    /**
     * @param name Name of the menu item
     * @param ingredients ArrayList<String> of ingredients
     * @param category category
     * @param priceString price of the menu item
     * @param sa array of special attributes
     * @return whether we were able to add menu item
     */
    public boolean addMenuItem(String name, ArrayList<String> ingredients,
                               String category, String priceString, MenuSpecialAttribute[] sa, String minutesToCook) {
        // if there was a null don't create the item
        if (name.isEmpty() || ingredients == null || category.isEmpty()
                || priceString.isEmpty() || minutesToCook.isEmpty()) {
            return false;
        }
        int timeToCook = Integer.parseInt(minutesToCook);

        MenuItem item = new MenuItem(name, ingredients, category, priceString,
                sa, timeToCook);
        I_Command cmd = new CmdAddMenuItem(infoagg, item);
        invoker.execute(cmd);
        return true;

    }

    public void setSeatingStrategy(SeatingStrategy strat) {
        I_Command cmd = new CmdSetSeatingStrat(infoagg, strat);
        invoker.execute(cmd);
    }

    public void resetStatistics() {
        I_Command cmd = new CmdResetStats(infoagg);
        invoker.execute(cmd);
    }

    public void setPrepStrategy(PrepStrategy strat) {
        I_Command cmd = new CmdSetPrepStrat(infoagg, strat);
        invoker.execute(cmd);
    }

    public void cookFood() {
        I_Command cmd = new CmdCookFood(infoagg);
        invoker.execute(cmd);
    }

    public void removeOrders(ArrayList<Order> partyOrders) {
        I_Command cmd = new CmdRemoveOrders(infoagg, partyOrders);
        invoker.execute(cmd);

    }

    public void generateTab(CustomerParty party) {
        I_Command cmd = new CmdGenerateTab(infoagg, party);
        invoker.execute(cmd);
    }

    public ArrayList<String> getTabs() {
        ArrayList<String> output = new ArrayList<String>();
        I_Command cmd = new CmdGetTabs(infoagg);
        TabCollection tabs = (TabCollection) invoker.execute(cmd);
        for (I_Tab tab : tabs) {
            output.add(tab.makeRegularTab());
        }
        return output;
    }

  }
